package com.LeeCode;

import java.util.Arrays;

/**
 * 人员站位的方案数 II
 */

public class Code3027 {
    public static void main(String[] args) {
        int[][] points = {{6, 2}, {4, 4}, {2, 6}};
        System.out.println(new Code3027().numberOfPairs(points));
    }

    public int numberOfPairs(int[][] points) {
        Arrays.sort(points, (a, b) -> {
            if (a[0] != b[0]) return a[0] - b[0];
            else return b[1] - a[1];
        });
        int ans = 0;
        for (int i = 0; i < points.length; i++) {
            int y0 = points[i][1];
            int maxY = Integer.MIN_VALUE;
            for (int j = i + 1; j < points.length; j++) {
                int y = points[j][1];
                if (y <= y0 && y > maxY) {
                    maxY = y;
                    ans++;
                }
            }
        }
        return ans;
    }
}
